# -*- coding: utf-8 -*-
"""
文件上传配置文件
"""
import os

# 获取项目根目录 (..../yoka-main)
ROOT_PATH = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
RESOURCES_DIR = os.path.join(ROOT_PATH, "resources")

# 用户上传文件和图片的保存地址
UPLOAD_FILE_DIR = os.path.join(RESOURCES_DIR, "files")
UPLOAD_CLAUSE_FILE_DIR = os.path.join(RESOURCES_DIR, "clauses")
UPLOAD_EDU_FILE_PATH = os.path.join(RESOURCES_DIR,  "edu")
UPLOAD_AUDIO_FILE_DIR = os.path.join(RESOURCES_DIR, "audio")

UPLOAD_IMAGE_DIR = os.path.join(RESOURCES_DIR, "images")
IMAGE_CHAT_ROOT_PATH = os.path.join(RESOURCES_DIR,  "image_chat")
print("UPLOAD_FILES_DIR:", UPLOAD_FILE_DIR)
print("UPLOAD_CLAUSE_FILE_DIR:", UPLOAD_CLAUSE_FILE_DIR)


# 文件上传相关配置
UPLOAD_CONFIG = {
    # 最大文件大小 (100MB)
    "MAX_FILE_SIZE": 100 * 1024 * 1024,
    
    # 支持的文件类型
    "ALLOWED_EXTENSIONS": {
        'pdf', 'doc', 'docx', 'txt'
    },
    
    # 上传超时时间 (秒)
    "UPLOAD_TIMEOUT": 300,
    
    # 分块上传大小 (1MB)
    "CHUNK_SIZE": 1024 * 1024,
    
    # 临时文件目录
    "TEMP_DIR": "temp_uploads",
    
    # 是否启用分块上传
    "ENABLE_CHUNKED_UPLOAD": True,
    
    # 重试次数
    "MAX_RETRIES": 3,
    
    # 重试延迟 (秒)
    "RETRY_DELAY": 1,
}

# 文件类型MIME映射
MIME_TYPES = {
    'pdf': 'application/pdf',
    'doc': 'application/msword',
    'docx': 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
    'txt': 'text/plain',
}

# 错误消息
ERROR_MESSAGES = {
    'FILE_TOO_LARGE': '文件大小超过限制 (最大100MB)',
    'INVALID_FILE_TYPE': '不支持的文件类型',
    'UPLOAD_TIMEOUT': '文件上传超时',
    'CLIENT_DISCONNECT': '客户端断开连接',
    'FILE_READ_ERROR': '文件读取失败',
    'SAVE_ERROR': '文件保存失败',
    'CONVERSION_ERROR': '文件格式转换失败',
}
